package com.seckill.Controller;

import com.seckill.Common.BaseResponse;
import com.seckill.Model.DO.Goods;
import com.seckill.Service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/a1")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/goods")
    public BaseResponse getGoodsList(@RequestParam("pageSize") Integer pageSize
                                     ,@RequestParam("pageNo") Integer pageNo){
        return goodsService.getGoodsPage(pageNo,pageSize);
    }

    @GetMapping("/goods/{id}")
    public BaseResponse getGoodsById(@RequestParam("id") Long id){
        return BaseResponse.success(goodsService.getGoodsById(id));
    }

    @DeleteMapping("/goods/{id}")
    public BaseResponse delete(@PathVariable("id") Long id){
        return BaseResponse.success(goodsService.removeById(id));
    }

    @PutMapping("/goods")
    public BaseResponse update(@RequestBody Goods goods){
        return BaseResponse.success(goodsService.updateById(goods));
    }

}
